package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportUserCertificate;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportUserCertificateDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-12-04 11:33:04
 */
public class TransportUserCertificateConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportUserCertificateConverts.class);

    public static List<TransportUserCertificateDTO> convert(List<TransportUserCertificate> transportUserCertificateList) {
        if (CollectionUtils.isEmpty(transportUserCertificateList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportUserCertificateDTO> transportUserCertificateListResult = Lists.newArrayList();
        for (TransportUserCertificate transportUserCertificate : transportUserCertificateList) {
            transportUserCertificateListResult.add(convert(transportUserCertificate));
        }
        return transportUserCertificateListResult;
    }

    public static TransportUserCertificateDTO convert(TransportUserCertificate transportUserCertificate) {
        try {
            return BeanUtils.copy(transportUserCertificate, TransportUserCertificateDTO.class);
        } catch (Exception e) {
            LOG.error("TransportUserCertificate到TransportUserCertificateDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportUserCertificate到TransportUserCertificateDTO转换失败", e);
        }
    }

    public static TransportUserCertificate convert(TransportUserCertificateDTO transportUserCertificateDTO) {
        try {
            return BeanUtils.copy(transportUserCertificateDTO, TransportUserCertificate.class);
        } catch (Exception e) {
            LOG.error("TransportUserCertificateDTO到TransportUserCertificate转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportUserCertificateDTO到TransportUserCertificate转换失败", e);
        }
    }
}